package com.learn;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class EncoImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar{

	@Override
	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
		Map<String,Object> attr = importingClassMetadata.getAnnotationAttributes(EnableEnco.class.getName());
		String[] packAttr = (String[]) attr.get("packages");
		List<String> packages = Arrays.asList(packAttr);
																			//EncoBeanPostProcessor这个很重要
		BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(EncoBeanPostProcessor.class);
		//设置属性
		bdb.addPropertyValue("packages", packages);
		
		//装配bean
		registry.registerBeanDefinition(EncoBeanPostProcessor.class.getName(), bdb.getBeanDefinition());
	}
}
